home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln1086.arc / BEEFUP.LTG < prev    next >
Text File  |  1986-09-15  |  9KB  |  302 lines

  1. Listings 1-7 for Beefing Up BASIC with Assembly
  2.  
  3. page 60,132
  4.  
  5. comment @
  6.  
  7. This is a single-line function which tests the specified bit in the given
  8. string.  The function returns -1 if the bit is set, else 0.
  9.  
  10. DEFINT A-Z
  11. DEF FNTB(A1$,A1) = (ASC(MID$(A1$,INT(A1/8)+1)) AND (2^(A1-INT(A1/8)*8))) <> 0
  12.  
  13. where A1$ is the bit map and A1% is the position to be tested.
  14.  
  15.     @
  16.  
  17. code segment byte public 'code'
  18. assume cs:code
  19.  
  20. comment *
  21.     
  22. TESTBIT      
  23. written for DCD Company 11/7/85 by Bill Borg
  24.  
  25. This routine will test the bit at a given position (0-2039) in a string.
  26. It is to be called by a program written for the IBM BASIC Compiler 2.0
  27. Three parameters are passed:
  28.     1) The string to be tested (up to 255 characters)
  29.     2) The position in the string to be checked (0-2039)
  30.     3) An integer to return -1 if the bit is set, else 0                 
  31.  
  32.     *
  33.  
  34. testbit proc far
  35. public testbit            ; define the entry point
  36.     push bp            ; establish addressability of the stack
  37.     mov bp,sp
  38.     mov bx,[bp+10]
  39.     mov si,[bx+2]        ; SI now points to the bit map to be tested
  40.                 ; compiler uses a 4-byte string descriptor
  41.     mov bx,[bp+8]
  42.     mov ax,[bx]        ; AX contains the position to be tested
  43.     mov bl,8    
  44.     div bl            ; divide the position by 8 to get the byte
  45.     mov bh,ah        ; save the remainder
  46.     xor ah,ah        ; clear the remainder from AH
  47.     add si,ax        ; SI now points to appropriate byte in the map
  48.     mov bl,byte ptr [si]    ; get the byte into BL
  49.     mov cl,bh        ; get the desired position within the byte
  50.     xor ax,ax        ; AX will return the result
  51.     ror bl,cl        ; roll the desired bit into first position
  52.     and bl,1        ; test the bit
  53.     jz exit            ; the bit was not set, leave 0 in AX
  54.     dec ax            ; the bit was set, return -1
  55. exit:è    mov bx,[bp+6]        ; get the address of the return integer
  56.     mov [bx],ax        ; return 0 or -1
  57.     pop bp            ; restore the base pointer
  58.     ret 6            ; clean up our stack
  59. testbit endp
  60.  
  61. comment *
  62.  
  63. SCRSAVE       
  64. written for DCD Company 3/10/86 by Bill Borg
  65.  
  66.      This is a routine that will save or restore an entire screen.
  67.     It waits until after a horizontal retrace to avoid a flash.
  68.      The check for mono/color is done within this routine.     
  69.      Two parameters are passed:
  70.          1)  The string variable which holds or will hold the screen
  71.             This string must be exactly 4000 bytes long.  This routine,
  72.             as written here, may thus not be called by the Interpreter.
  73.          2)  The function ( 0 to save, NOT 0 to restore)
  74.     *
  75.  
  76. scrsave proc far
  77. public scrsave        ; define entry point of the routine
  78.  
  79.     push bp        ; establish addressability of the stack
  80.     mov bp,sp
  81.     push ds        ; save data segment for return
  82.     push es        ; save extra segment for return
  83.  
  84. scr_check:        ; check for color or mono
  85.     mov ah,15    ; function to get current video state
  86.     int 10h        ; video bios call
  87.             ; assume monochrome
  88.     mov cx,0b000h    ; address of screen buffer for mono
  89.     mov dx,03bah    ; address of 6845 chip for mono          
  90.     cmp al,7    ; is it mono?
  91.     jz opt_check    ; it sure is!
  92.     mov cx,0b800h    ; no - it must be color                        
  93.     mov dx,03dah    ; address of 6845 chip for CGA             
  94. opt_check:
  95.     mov bx,[bp+6]    ; get option
  96.     mov ax,[bx]      ; AX holds the option word
  97.     mov bx,[bp+8]    ; get address of string descriptor
  98.     cmp al,0    ; are you saving or restoring?
  99.     jne put_scr    ;
  100. get_scr:        ; routine to save the screen
  101.     mov si,0    ; offset 0 into the screen
  102.     mov di,[bx+2]   ; offset of the string
  103.     mov ds,cx    ; put screen segment as the source
  104.     jmp do_it    ; go do the move    
  105. put_scr:        ; routine to restore the screen from a string
  106.     mov si,[bx+2]    ; offset of the string is the source
  107.     mov di,0    ; offset 0 into the screen
  108.     mov es,cx    ; put screen segment as the destination    
  109. do_it:            ; perform the moveè    mov cx,2000    ; move 2000 words
  110.    p1:            ; wait for horizontal retrace
  111.     in al,dx    ; get status
  112.     test al,1    ; is it low?
  113.     jnz p1       ; wait until it is
  114.     cli        ; disable interrupts
  115.    p2:  
  116.     in al,dx    ; get status
  117.     test al,1    ; is it high?
  118.     jz p2         ; wait until it is
  119. move:  
  120.     movsw        ; do the move
  121.     sti        ; enable interrupts
  122.     loop p1       ; go until all 2000 words have been moved
  123. finish:
  124.     pop es
  125.     pop ds
  126.     pop bp
  127.     ret 4        ; restore the four bytes on the stack
  128. ;
  129. scrsave endp
  130.  
  131. comment *
  132.  
  133. GETVER
  134. written for DCD Company 6/12/85 by Bill Borg
  135.  
  136.     This routine will return the major and minor version numbers of DOS.
  137.  
  138.     One parameter is passed:
  139.  
  140.     1) An integer to return the major version number (2,3,etc.) in the 
  141.        low byte and the minor version number (0,10,20,etc.) in the high
  142.        byte.
  143.     *
  144.  
  145. getver proc far        ; all calls from BASIC are far calls
  146. public getver        ; declare entry point for external call
  147.  
  148.     push bp        ; establish addressability of stack
  149.     mov bp,sp
  150.  
  151.     mov ah,30h    ; function to get DOS Version Number
  152.     int 21h        ; make the DOS call
  153.                 ; AX returns with the minor/major versions
  154.     mov bx,[bp+6]    ; get the address of the return integer
  155.     mov [bx],ax    ; move minor/major back to BASIC data segment
  156.  
  157.     pop bp        ; restore BASIC's base pointer
  158.     ret 2        ; restore the two bytes that we passed
  159.  
  160. getver endp
  161.  
  162. comment *
  163. è    DATESET      
  164.  
  165.     This routine will take the specified file and set its time to 12:00p
  166.     and its date to whatever is passed.
  167.  
  168.     Three parameters are passed:
  169.  
  170.     1) The date in three-byte YMD format where:                       
  171.        Y = 80-199 (80 = 1980)   M = 1-12   D = 1-31
  172.     2) ASCIIZ string representing the path/name of the file to be stamped
  173.     3) An integer to return 0 for a successful operation, or -1 if an error
  174.        occurred on the open, the set, or the close.
  175.  
  176.     *
  177. dateset proc far
  178. public dateset            ; declare entry point for external call
  179.     push bp            ; establish addressability of stack
  180.     mov bp,sp
  181. open_file:
  182.     mov bx,[bp+8]        ; get the pointer to the file name
  183.     mov dx,[bx+2]        ; DX points to the filename
  184.     sub al,al        ; clear AL to open for read
  185.     mov ah,3Dh        ; function to open a file
  186.     int 21h            ; call DOS
  187.     jc no_dice        ; carry flag is set on an error
  188.     push ax            ; save the file handle
  189. set_date:
  190.     mov bx,[bp+10]        ; get the pointer to the date
  191.     mov si,[bx+2]        ; SI will point to the three-byte date
  192. year:
  193.     mov al,[si]        ; get the year
  194.     sub al,80        ; put the year into DOS terms (0-119)
  195.     xor dx,dx        ; clear DX   
  196.     mov dh,al        ; DX will end up holding the whole date
  197.                 ; DX is "xyyyyyyy/xxxxxxxx"
  198. month:
  199.     mov dl,[si+1]        ; get the month
  200.                 ; DX is xyyyyyyy/xxxxmmmm
  201.     mov cl,4
  202.     shl dl,cl        ; shift the month into the four high bits
  203.                 ; DX is xyyyyyyy/mmmmxxxx
  204.     rol dx,1        ; roll DX into the form "yyyyyyym/mmmxxxxx"
  205. day:
  206.     mov al,[si+2]        ; get the day
  207.     or dl,al        ; mov the day into DX
  208.                 ; DX is "yyyyyyym/mmmddddd"
  209. set_time:
  210.     mov cx,0110000000000000b; set the time to 12:00:00p
  211.                 ; time is hhhh/mmmmmm/xxxxx
  212. do_set:
  213.     mov ah,57h        ; function to get/set the time
  214.     mov al,1        ; code to set the time (rather than get)
  215.     pop bx            ; retrieve the file handle that we pushed
  216.     int 21h            ; call DOS
  217.     jc no_dice        ; carry flag is set on errorèclose_file:
  218.     mov ah,3Eh        ; function to close a file
  219.     int 21h            ; call DOS
  220.     jc no_dice        ; carry flag is set on error
  221.     sub ax,ax        ; return an error code of 0        
  222.     jmp get_out
  223. no_dice:            ; we hit an error somewhere
  224.     mov ax,-1        ; return error code of -1
  225. get_out:
  226.     mov bx,[bp+6]
  227.     mov [bx],ax        ; return an error code of 0 or -1
  228.     pop bp
  229.     ret 6            ; restore the stack
  230.  
  231. dateset endp
  232.  
  233. comment *
  234.  
  235. PRTSC
  236. written for DCD Company 9/3/85 by Bill Borg
  237.  
  238.     This routine forces a print screen.
  239.     No parameters are passed.
  240.  
  241.     *
  242. prtsc proc far
  243. public prtsc               ; establish entry point for the call
  244.     push bp            ; establish addressability of the stack
  245.     mov bp,sp
  246.     int 5h            ; interrupt five to do the print screen
  247.     pop bp            ; restore BASIC's base pointer
  248.     ret            ; return
  249. prtsc endp
  250.  
  251. comment *
  252.  
  253. MEMSIZE
  254. written for DCD Company 1/7/86 by Bill Borg
  255.  
  256.     This routine returns the number of contiguous 1K blocks of memory
  257.     in the system.
  258.     An integer is passed to return the number.
  259.     *
  260.  
  261. memsize proc far
  262. public memsize            ; establish entry point for the call
  263.     push bp            ; establish addressability of the stack
  264.     mov bp,sp
  265.     int 12h            ; make the memory_size_determine call
  266.     mov bx,[bp+6]        ; get the address of the return integer
  267.     mov [bx],ax        ; AX has the number of 1K blocks
  268.     pop bp            ; restore BASIC's base pointer
  269.     ret 2            ; restore the stack and return
  270. memsize endp
  271. ècomment *
  272.  
  273. VIDEO
  274.  
  275. written for DCD Company 2/7/86 by Bill Borg
  276.  
  277.      This is a generic routine that makes an INT 10H call.
  278.      Four parameters are passed corresponding to CX,DX,AX,BX.
  279.      All parameters must be passed, although not all need be defined.
  280.      *
  281.  
  282. video proc far
  283. public video        ; establish the entry point for the call
  284.     push bp        ;establish addressability of the stack
  285.     mov bp,sp
  286.     mov bx,[bp+12]    ; CX
  287.     mov cx,[bx]
  288.     mov bx,[bp+10]    ; DX
  289.     mov dx,[bx]
  290.      mov bx,[bp+8]    ; AX
  291.     mov ax,[bx]
  292.     mov bx,[bp+6]    ; BX
  293.     mov bx,[bx]
  294.         int 10h
  295.     pop bp
  296.     ret 8        ;restore the eight bytes on the stack
  297. video endp
  298.  
  299. code ends     
  300.  
  301. end
  302.